home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_066 / melt / melt.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  160 lines

  1. /***********************************************************************\
  2. *                                    *
  3. *    Melt -- Yet another screen hack.  This is the direct        *
  4. *        result of playing with Tilt too late at night.        *
  5. *        Thank you Leo.                        *
  6. *                                    *
  7. *                Stephen Coy                *
  8. *                15407 Garden St. Apt. C            *
  9. *                Sumner, WA  98390            *
  10. *                uw-beaver!ssc-vax!coy            *
  11. *                                    *
  12. *    This program may be freely distributed, modified and        *
  13. *    criticized.  Use it as you see fit.                *
  14. *                                    *
  15. *    Note:    This compiles with Manx using 32-bit ints.  If        *
  16. *        you want 16-bit ints you should just have to        *
  17. *        clean up melt().                    *
  18. *                                    *
  19. \***********************************************************************/
  20.  
  21. #include <exec/types.h>
  22. #include <intuition/intuition.h>
  23.  
  24. #define DEPTH    2
  25.  
  26. extern void    *OpenLibrary(), *OpenWindow(), *OpenScreen(), *GetMsg();
  27.  
  28. struct NewScreen scrdef = {
  29.         0, 0, 0, 0, DEPTH,
  30.         0, 1,
  31.         NULL,
  32.         CUSTOMSCREEN,
  33.         NULL,
  34.         (UBYTE *) "Help me!",
  35.         NULL, NULL
  36. };
  37.  
  38. struct NewWindow windef = {
  39.         0, 30, 140, 10,
  40.         -1, -1,
  41.         CLOSEWINDOW,
  42.         WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH | 
  43.         SMART_REFRESH | ACTIVATE,
  44.         NULL, NULL,
  45.         (UBYTE *) "Melt",
  46.         NULL, NULL,
  47.         0, 0, 0, 0,
  48.         WBENCHSCREEN
  49. };
  50.  
  51. struct Screen    *scr;
  52. struct Window    *win;
  53. struct TmpRas    tmpras;
  54. void        *IntuitionBase, *GfxBase;
  55.  
  56. main()
  57. {
  58.     struct Screen    *wb;
  59.     struct RastPort    *rp;
  60.     struct BitMap    *wbm, *mbm;
  61.     long    x, y, n;
  62.     register int i;
  63.  
  64.     openstuff();
  65.  
  66.     wb = win->WScreen;
  67.     scrdef.LeftEdge  = wb->LeftEdge;
  68.     scrdef.TopEdge   = wb->TopEdge;
  69.     scrdef.Width     = wb->Width;
  70.     scrdef.Height    = wb->Height;
  71.     scrdef.ViewModes = wb->ViewPort.Modes;
  72.     if(!(scr = OpenScreen(&scrdef)))
  73.       die("Screen open failed!");
  74.     ScreenToBack(scr);
  75.  
  76.     rp = &scr->RastPort;
  77.     mbm = rp->BitMap;
  78.     wbm = win->WScreen->RastPort.BitMap;
  79.     BltBitMap(wbm, 0L, 0L, mbm, 0L, 0L,
  80.           (long)scrdef.Width, (long)scrdef.Height,
  81.           0xc0L, 0xffL, NULL);
  82.     ScreenToFront(scr);
  83.     melt(rp, mbm);
  84.     closestuff();
  85. }
  86.  
  87.  
  88. melt(rp, bitmap)
  89. struct RastPort    *rp;
  90. struct BitMap    *bitmap;
  91. {
  92.     int    class;
  93.     struct    IntuiMessage    *message;
  94.     int    x, y,            /* start positions         */
  95.         dx, dy,            /* offsets                 */
  96.         u, v;            /* size                    */
  97.     int    TempA[32];        /* temp buffer             */
  98.     char    mask;            /* bit-plane mask for blitter    */
  99.  
  100.     FOREVER {
  101.       message = (struct IntuiMessage *)GetMsg(win->UserPort);
  102.       if(message != (struct IntuiMessage *)NULL) {
  103.         class = message->Class;
  104.         ReplyMsg(message);
  105.         if(class == CLOSEWINDOW) {
  106.           return;
  107.         }
  108.       }
  109.       for(mask=1; mask<+(1<<DEPTH)-1; mask*=2) {
  110.         u = RangeRand(scr->Width - 3) + 1;
  111.         v = RangeRand(scr->Height - 3) + 1;
  112.         x = RangeRand(scr->Width - 1 - u) + 1;
  113.         y = RangeRand(scr->Height - 2 - v) + 1; 
  114.         dx = RangeRand(3) - 1;
  115.         dy = RangeRand(3);  /* also try dy = RangeRand(3) - 1;  */
  116.  
  117.         BltBitMap(bitmap, x, y,
  118.                   bitmap, x+dx, y+dy,
  119.                   u, v, 0x0c0, mask, TempA);
  120.       }     /* end of for mask */
  121.  
  122.     }     /* end of FOREVER */
  123. }     /* end of melt */
  124.  
  125. openstuff()
  126. {
  127.     if(!(IntuitionBase = OpenLibrary("intuition.library", 0L))) {
  128.       puts("Intuition missing.");
  129.       exit(100);
  130.     }
  131.  
  132.     if(!(GfxBase = OpenLibrary("graphics.library", 0L))) {
  133.       puts("Art shop clode.");
  134.       exit(100);
  135.     }
  136.  
  137.     if(!(win = OpenWindow(&windef))) {
  138.       puts("Window painted shut.");
  139.       closestuff();
  140.       exit(100);
  141.     }
  142. }
  143.  
  144. die(str)
  145. char    *str;
  146. {
  147.     puts(str);
  148.     closestuff();
  149.     exit(100);
  150. }
  151.  
  152. closestuff()
  153. {
  154.     if(tmpras.RasPtr) FreeRaster(tmpras.RasPtr, 320, 200);
  155.     if(scr)           CloseScreen(scr);
  156.     if(win)           CloseWindow(win);
  157.     if(GfxBase)       CloseLibrary(GfxBase);
  158.     if(IntuitionBase) CloseLibrary(IntuitionBase);
  159. }
  160.